﻿@model IEnumerable<Property4U.Models.Order>

@{
    ViewBag.Title = "Orders";
}

@helper  ConvertBytes(string IBytes)
{

    double IBytesI = Convert.ToDouble(IBytes);
    string sSize = string.Empty;

    if (IBytesI >= 1073741824)
    {
        @(String.Format("{0:##.##}", IBytesI / 1073741824) + " GB");
    }
    else if (IBytesI >= 1048576)
    {
        @(String.Format("{0:D}", IBytesI / 1048576) + " MB");
    }
    else if (IBytesI >= 1024)
    {
        @(String.Format("{0:##.##}", IBytesI / 1024) + " KB");
    }
    else if (IBytesI > 0 && IBytesI < 1024)
    {
        @(IBytes.ToString() + " bytes");
    }
}

<div class="row">
    <!-- Page Header -->
    <div class="col-lg-12">
        <h1 class="page-header">@ViewBag.Title</h1>
    </div>
    <!--End Page Header -->
</div>

@if (Request.IsAuthenticated && User.IsInRole("Agent"))
{
    <p>
        @Html.ActionLink("Create New", "Create")
    </p>
}
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.ID)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Title)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Description)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Size)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.NumberOfAds)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.ZipFilePath)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.ZipFileSize)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.AdsDuration)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Date)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.OrderStatus)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Remedies)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.ID)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Title)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Description)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Size)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.NumberOfAds)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ZipFilePath)
        </td>
        <td>
            @ConvertBytes(item.ZipFileSize.ToString())
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.AdsDuration)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Date)
        </td>
        <td>
            <span class="progress status-@item.OrderStatus">
                @Html.DisplayFor(modelItem => item.OrderStatus)
            </span>
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Remedies)
        </td>
        <td>
            @if (Request.IsAuthenticated && User.IsInRole("Agent"))
            {
                @Html.ActionLink("Edit", "Edit", new { id = item.ID }) @(" | ")
                @Html.ActionLink("Delete", "Delete", new { id = item.ID }) @(" | ")
            }
            @Html.ActionLink("Details", "Details", new { id = item.ID })
        </td>
    </tr>
}

</table>
